package com.yueya.business.nursing.model;

import java.util.Map;

import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.yueya.common.util.DateUtil;
import com.yueya.common.util.UUIDGenerator;

@SuppressWarnings("serial")
public class NursingItems extends Model<NursingItems> {
	
	public static NursingItems dao = new NursingItems();
	
	public boolean  save(NursingItems dao) {
		dao.set("nursing_base_id", UUIDGenerator.getUUID());
    	dao.set("create_time",DateUtil.getDate(DateUtil.timeFormat));
		return dao.save();
	}
	
	public boolean  update(NursingItems dao) {
    	dao.set("update_time",DateUtil.getDate(DateUtil.timeFormat));
		return dao.save();
	}
	
	public boolean  remove(NursingItems dao) {
    	dao.set("del_flag","1");
		return dao.save();
	}
	
	
	@SuppressWarnings("rawtypes")
	public Page paginate (int pageNumber,int pageSize,Map<String,String> map) {
		 String select =" select reserv.*  ";
	        StringBuffer sql = new StringBuffer(" from  (select nb.*, sb.*,eb.user_emp_id ,eb.name from jg_nursing_base nb  ");
	        sql.append(" LEFT JOIN jg_emp_base eb on  nb.emp_id =eb.user_emp_id  ");
	        sql.append(" LEFT JOIN v_senior_base sb on  sb.senior_id =nb.senior_id ");
	        sql.append(" where nb.del_flag='0' )");
	        
	        for (Map.Entry<String, String> entry : map.entrySet()) {
	          if(entry.getValue().contains("%")) {
	        	  sql.append(" and reserv." +entry.getKey()+ "like '"+entry.getValue()+"'  ");
	          }else if(StrKit.notBlank(entry.getValue())) {
	       	   sql.append(" and reserv." +entry.getKey()+ " ='"+entry.getValue()+"'  ");
	       	  }           
	        }  
	        
	       if(StrKit.notBlank(map.get("order"))) {
	     	  sql.append(" order by  reserv."+map.get("order"));
	        }else {
	        	 sql.append(" order by reserv.reservation_date desc" );
	        }
	        
	    	return dao.paginate(pageNumber, pageSize, select, sql.toString());
	}
	
	


}
